import {ErrorCode} from "./ErrorCode";
import {Pos} from "../utils/Pos";

export default class TokenizeError extends Error {

    private err: ErrorCode;
    private pos: Pos;

    constructor(err: ErrorCode, pos: Pos);
    constructor(err: ErrorCode, row: number, col: number);

    constructor(err: ErrorCode, pos: Pos | number, col?: number) {
        super();
        if (pos instanceof Pos) {
            this.err = err;
            this.pos = pos;
        } else {
            this.err = err;
            this.pos = new Pos(pos, col || 0);
        }
    }

    getErr(): ErrorCode {
        return this.err;
    }

    getPos(): Pos {
        return this.pos;
    }

    toString(): string {
        return `Tokenize Error: ${this.err.toString()}, at: ${this.pos.toString()}`;
    }
}